local ma__shuliang = fk.CreateSkill {
  name = "ma__shuliang",
}

Fk:loadTranslationTable{
  ["ma__shuliang"] = "戍凉",
  ["@@ma__shuliang-turn"] = "戍凉",
  [":ma__shuliang"] = "每回合限一次，当一名角色成为【杀】的目标后，你可以令其获得其场上的所有牌，且本回合其手牌中的装备牌均视为【闪】。<br>"..
    "若如此做，其抵消此【杀】后将手牌调整至体力上限。",

  ["#ma__shuliang-invoke"] = "戍凉：你可以令 %dest 收回其场上的牌，且其装备牌本回合视为【闪】",

  ["$ma__shuliang1"] = "今君困顿，扶援相助。",
  ["$ma__shuliang2"] = "恤君之患，以相扶援。",
}

ma__shuliang:addEffect(fk.TargetConfirmed, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(ma__shuliang.name) and data.card.trueName == "slash" and not target.dead and
    player:usedSkillTimes(ma__shuliang.name, Player.HistoryTurn) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = ma__shuliang.name,
      prompt = "#ma__shuliang-invoke::"..target.id,
    }) then
      event:setCostData(self, {tos = {target}})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
      if #target:getCardIds("ej") > 0 and not target.dead then
        room:obtainCard(target, target:getCardIds("ej"), false, fk.ReasonPrey, player, ma__shuliang.name)
      end
    player.room:setPlayerMark(target, "@@ma__shuliang-turn", 1)
    data.extra_data = data.extra_data or {}
    data.extra_data.ma__shuliang = data.extra_data.ma__shuliang or {}
    table.insertIfNeed(data.extra_data.ma__shuliang, target)
  end,
})

ma__shuliang:addEffect("filter", {
  mute = true,
  card_filter = function(self, card, player)
    return player:getMark("@@ma__shuliang-turn") > 0 and
      card.type == Card.TypeEquip and table.contains(player:getCardIds("h"), card.id)
  end,
  view_as = function(self, player, card)
    return Fk:cloneCard("jink", card.suit, card.number)
  end,
})

ma__shuliang:addEffect(fk.CardEffectCancelledOut, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if data.card.trueName == "slash" and data.to:getMark("@@ma__shuliang-turn") > 0 then
      local e = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
      if e then
        local use = e.data
        if use.extra_data and use.extra_data.ma__shuliang and table.contains(use.extra_data.ma__shuliang, data.to) and not data.to.dead then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.to
    --if to:isNude() then return end
    local target_num = to.maxHp
    local cur_num = to:getHandcardNum()
        if cur_num > target_num then
      local discard_num = cur_num - target_num
      room:askToDiscard(to, {
        min_num = discard_num,
        max_num = discard_num,
        include_equip = false,
        skill_name = ma__shuliang.name,
        cancelable = false,
      })
        elseif cur_num < target_num then
      to:drawCards(math.min(target_num - cur_num, 20), ma__shuliang.name)
    end
  end,
})

return ma__shuliang